package com.ourcraft.informationcollectionsystem.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ourcraft.informationcollectionsystem.utils.statusCode.DataReportFormStatus;
import lombok.*;
import org.springframework.stereotype.Service;

@Data
@NoArgsConstructor
@TableName("DataReportForm")
public class DataReportForm {
    @TableId(type = IdType.AUTO)
    private Integer formId;
    private Integer investigationId;
    private Integer companyId;
    private Integer formStartTotalNum;
    private Integer formEndTotalNum;
    private String formDecreaseType;
    private String formFirstReason;
    private String formSecondReason;
    private String formThirdReason;
    private String formReasonDescription;
    @Setter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
    private DataReportFormStatus formExamineStatus;

    public DataReportForm(Integer investigationId,
                          Integer companyId,
                          Integer formStartTotalNum) {
        this.investigationId = investigationId;
        this.companyId = companyId;
        this.formStartTotalNum = formStartTotalNum;
        this.formExamineStatus = DataReportFormStatus.NOT_FILL;
    }

    public DataReportForm(JSONObject param) {
        var ID = param.getInteger("formID");
        this.formId = ID != null ? ID : param.getInteger("formId");
        this.investigationId = param.getInteger("investigationId");
        this.companyId = param.getInteger("companyId");
        this.formStartTotalNum = null;//param.getInteger("formStartTotalNum");
        this.formEndTotalNum = param.getInteger("formEndTotalNum");
        this.formDecreaseType = param.getString("formDecreaseType");
        this.formFirstReason = param.getString("formFirstReason");
        this.formSecondReason = param.getString("formSecondReason");
        this.formThirdReason = param.getString("formThirdReason");
        this.formReasonDescription = param.getString("formReasonDescription");
        this.formExamineStatus = DataReportFormStatus.build(param.getInteger("formExamineStatus"));
    }
    public void setFormExamineStatus(Integer formExamineStatus) {
        this.formExamineStatus = DataReportFormStatus.build(formExamineStatus);
    }

    public void setFormExamineStatus(DataReportFormStatus formExamineStatus) {
        this.formExamineStatus = formExamineStatus;
    }

    public Integer getFormExamineStatus() {
        return formExamineStatus.status;
    }

    public DataReportFormStatus getStatus() {
        return this.formExamineStatus;
    }
}
